var _util = require('util/util.js');
const { getServerURL, request } = require('../util/util');

var _cart_service = {
    getCart: function (resolve, reject) {
        _util.request({
            url: _util.getServerURL('cart/cartItems'),
            method: "GET",
            success: resolve,
            error: reject,
        })
    },

    insertItem: function (workingItemId, resolve, reject) {
        _util.request({
            url: _util.getServerURL('cart/insertCartItem'),
            data: { workingItemId },
            method: "POST",
            success: resolve,
            error: reject,
        })
    },

    removeItem: function (workingItemId, resolve, reject) {
        _util.request({
            url: _util.getServerURL('cart/removeCartItem'),
            data: { workingItemId },
            method: "GET",
            success: resolve,
            error: reject,
        })
    },

    updateItem: function (workingItemId, quantity, resolve, reject) {
        _util.request({
            url: _util.getServerURL('cart/updateCartItem'),
            data: { workingItemId, quantity },
            method: "POST",
            success: resolve,
            error: reject,
        })
    },
}

module.exports = _cart_service;